package chan.module.project.database.vastdata.vastbase;

import cn.com.vastbase.util.PGobject;
import chan.module.project.database.vastdata.DatabaseUtil;

import java.sql.*;

public class TestVaseBase {
    private static final String JDBC_URL = "jdbc:vastbase://10.10.92.145:5432/btongdvp?currentSchema=dvp_etl3";
    private static final String JDBC_USER = "tongdvp";
    private static final String JDBC_PASSWORD = "qazWSX@123";
    public static void main(String[] args) {
        insert();
    }
    public static void queryUsers() {
        String sql1 = "SELECT id, c_date, c_time, c_timestamp, c_smalldatetime, c_tinyint, c_smallint, c_integer, c_binary_integer, c_bigint, c_boolean, c_char, c_character, c_nchar, c_varchar, c_character_varying, c_varchar2, c_nvarchar2, c_nvarchar, c_text, c_clob, c_blob, c_raw, c_bytea, c_bit, c_bit_varying, c_uuid, c_int4range, c_int8range, c_numrange, c_tsrange, c_tstzrange, c_daterange, c_xml, c_money FROM \"ALL_TYPES_TABLE_1\" WHERE id=1; ";
        String sql2 = "INSERT INTO \"ALL_TYPES_TABLE_2\" (\n" +
                "    id, \n" +
                "    c_date, \n" +
                "    c_time, \n" +
                "    c_timestamp, \n" +
                "    c_smalldatetime, \n" +
                "    c_tinyint, \n" +
                "    c_smallint, \n" +
                "    c_integer, \n" +
                "    c_binary_integer, \n" +
                "    c_bigint, \n" +
                "    c_boolean, \n" +
                "    c_char, \n" +
                "    c_character, \n" +
                "    c_nchar, \n" +
                "    c_varchar, \n" +
                "    c_character_varying, \n" +
                "    c_varchar2, \n" +
                "    c_nvarchar2, \n" +
                "    c_nvarchar, \n" +
                "    c_text, \n" +
                "    c_clob, \n" +
                "    c_blob, \n" +
                "    c_raw, \n" +
                "    c_bytea, \n" +
                "    c_bit, \n" +
                "    c_bit_varying, \n" +
                "    c_uuid, \n" +
                "    c_int4range, \n" +
                "    c_int8range, \n" +
                "    c_numrange, \n" +
                "    c_tsrange, \n" +
                "    c_tstzrange, \n" +
                "    c_daterange, \n" +
                "    c_xml, \n" +
                "    c_money\n" +
                ") VALUES (\n" +
                "    ?, \n" +
                "    ?, \n" +
                "    ?, \n" +
                "    ?, \n" +
                "    ?, \n" +
                "    ?, \n" +
                "    ?, \n" +
                "    ?, \n" +
                "    ?, \n" +
                "    ?, \n" +
                "    ?, \n" +
                "    ?, \n" +
                "    ?, \n" +
                "    ?, \n" +
                "    ?, \n" +
                "    ?, \n" +
                "    ?, \n" +
                "    ?, \n" +
                "    ?, \n" +
                "    ?, \n" +
                "    ?, \n" +
                "    ?, \n" +
                "    ?, \n" +
                "    ?, \n" +
                "    ?, \n" +
                "    ?, \n" +
                "    ?, \n" +
                "    ?, \n" +
                "    ?, \n" +
                "    ?, \n" +
                "    ?, \n" +
                "    ?, \n" +
                "    ?, \n" +
                "    ?, \n" +
                "    ?\n" +
                ");";
        Connection conn = null;
        PreparedStatement pstmt = null;
        ResultSet rs = null;
        try{
            Class.forName("cn.com.vastbase.Driver");
            conn = DriverManager.getConnection(JDBC_URL, JDBC_USER, JDBC_PASSWORD);
            pstmt = conn.prepareStatement(sql1);
            rs = pstmt.executeQuery();
            ResultSetMetaData metaData = rs.getMetaData();

            while (rs.next()) {
                Object value = rs.getObject(1);
                System.out.println(value);
            }

        } catch (Exception e) {
            e.printStackTrace();
        }finally {
            DatabaseUtil.close(conn,pstmt,rs);
        }
    }
    public static void insert() {
        String sql = "insert into \"TEST_money_TYPE_1\"(c_money)values(?)";
        Connection conn = null;
        PreparedStatement pstmt = null;
        ResultSet rs = null;
        try{
            Class.forName("cn.com.vastbase.Driver");
            conn = DriverManager.getConnection(JDBC_URL, JDBC_USER, JDBC_PASSWORD);
            pstmt = conn.prepareStatement(sql);
            PGobject pGobject = new PGobject();
            pGobject.setType("MONEY");
            pGobject.setValue(null);
            pstmt.setObject(1,pGobject);
            pstmt.execute();
        } catch (Exception e) {
            e.printStackTrace();
        }finally {
            DatabaseUtil.close(conn,pstmt,rs);
        }
    }
}
